package com.haoshuang.zhouzhoubang.ui.vm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.OrderBean5
import com.haoshuang.zhouzhoubang.model.bean.OrderDetail2Bean
import com.haoshuang.zhouzhoubang.model.bean.PriceBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ComfirmDoorInViewModel : BaseViewModel() {
    val getData55 = StatefulMutableLiveData<ArrayList<PriceBean>>()
    fun getData55(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ArrayList<PriceBean>>("api/master_order/getCostList", *params,
                onStart = {
                    getData55.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData55.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData55.value = StateData.Success(it)
                })
        }
    }
    val getData2 = StatefulMutableLiveData<ArrayList<PriceBean>>()
    fun getData2(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ArrayList<PriceBean>>("api/master_order/getCostList", *params,
                onStart = {
                    getData2.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData2.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData2.value = StateData.Success(it)
                })
        }
    }
    val getData5 = StatefulMutableLiveData<OrderBean5>()
    fun getData5(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<OrderBean5>("api/master_order/get_master_order_base", *params,
                onStart = {
                    getData5.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData5.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData5.value = StateData.Success(it)
                })
        }
    }

    val getData = StatefulMutableLiveData<Any>()
        fun getData(vararg params: Pair<String, Any?>) {
            rxLifeScope.launch {
                request<Any>("api/master_order/confirm_door_visit", *params,
                    onStart = {
                        getData.value = StateData.Loading
                    },
                    onError = { code, msg ->
                        getData.value = StateData.Error(code, msg)
                    }, onSuccess = {
                        getData.value = StateData.Success(it)
                    })
            }
        }

    /**
     * 上传核销码
     */
    val uploadWriteOffCodeData = StatefulMutableLiveData<Any>()
    fun uploadWriteOffCode(id: String?, url: String?) = netRequest {
        start { uploadWriteOffCodeData.value = StateData.Loading }
        request { ApiRepo.uploadWriteOffCodeImage(id, url) }
        success { uploadWriteOffCodeData.value = StateData.Success(it) }
        error { code, msg ->
            uploadWriteOffCodeData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 获取订单详情
     */
    val getOrderDetailData = StatefulMutableLiveData<OrderDetail2Bean>()
    fun getOrderDetail(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<OrderDetail2Bean>("api/master_order/get_master_order_detail", *params,
                onStart = {
                    getOrderDetailData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getOrderDetailData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getOrderDetailData.value = StateData.Success(it)
                })
        }
    }

}